package com.yanqu.road.server.cmd.zhaoshang;

import com.yanqu.road.entity.enums.eSystemId;
import com.yanqu.road.pb.zhaoshang.ZhaoShangProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.manger.config.SystemOpenMgr;
import com.yanqu.road.server.manger.zhaoshang.ZsConfigMgr;
import com.yanqu.road.server.manger.zhaoshang.ZsMgr;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.CrossProtocol;
import com.yanqu.road.server.protocol.GameErrorCode;
import com.yanqu.road.server.protocol.Protocol;

@Cmd(code = Protocol.S_ZS_PROJECT_SEARCH, desc = "查询玩家相关的项目")
public class ZsProjectSearchCmd extends AbstractCommand {

    private long searchUserAliasId;

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        ZhaoShangProto.ZsProjectListReqMsg reqMsg = ZhaoShangProto.ZsProjectListReqMsg.parseFrom(packet.getBytes());
        searchUserAliasId = reqMsg.getSearchUserAliasId();
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        if(!SystemOpenMgr.systemOpen(player, eSystemId.ZhaoShang.getValue())){
            ret = GameErrorCode.E_SYSTEM_NO_OPEN;
            return;
        }
        if(!ZsMgr.isZsSystemOpenTime()){
            ret = GameErrorCode.E_SYSTEM_NO_OPEN;
            return;
        }

        //直接上跨服查找
        ZhaoShangProto.CrossZsProjectListReqMsg.Builder crossReqMsg = ZhaoShangProto.CrossZsProjectListReqMsg.newBuilder();
        crossReqMsg.setSearchUserAliasId(searchUserAliasId);
        crossReqMsg.setListNumLimit(ZsConfigMgr.getZsListSize());
        player.sendPacket(CrossProtocol.C2_ZHAO_SHANG_PROJECT_SEARCH, crossReqMsg);

    }

    @Override
    public void sendData(GamePlayer player) {
        if(ret != 0){
            ZhaoShangProto.ZsProjectListRespMsg.Builder respMsg = ZhaoShangProto.ZsProjectListRespMsg.newBuilder();
            respMsg.setRet(ret);
            respMsg.setSearchUserAliasId(searchUserAliasId);
            player.sendPacket(Protocol.U_ZS_PROJECT_LIST, respMsg);
        }
    }
}
